package com.smart.campus.controller;

import com.smart.campus.dto.SysUser;
import com.smart.campus.pojo.PagedResponse;
import com.smart.campus.pojo.ResponseResult;
import com.smart.campus.service.SysUserServiceFeign;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Api(tags = "用户管理")
@Slf4j
@RestController
@RequestMapping(value = "sysUser")
public class SysUserController {
    @Autowired
    private SysUserServiceFeign sysUserServiceFeign;

    @ApiOperation(value = "列表查询", httpMethod = "POST", notes = "列表查询")
    @RequestMapping(value = "findUserList")
    public ResponseResult<List<SysUser>> findUserList(@RequestBody SysUser sysUser){
        return new ResponseResult<>(200,"查询成功",sysUserServiceFeign.findUserList(sysUser));
    }
    @ApiOperation(value = "列表分页查询", httpMethod = "POST", notes = "列表分页查询")
    @RequestMapping(value = "pageUser")
    public ResponseResult<PagedResponse<SysUser>> pageUser(@RequestBody SysUser sysUser, @RequestParam(value = "pageNum")Integer pageNum,@RequestParam(value = "pageSize")Integer pageSize){
        return new ResponseResult<>(200,"分页查询成功",sysUserServiceFeign.pageUser(sysUser,pageNum,pageSize));
    }
    @ApiOperation(value = "回显信息", httpMethod = "GET", notes = "回显信息")
    @RequestMapping(value = "findUserById")
    public ResponseResult<SysUser> findUserById(@RequestParam(value = "userId")Long userId){
        return new ResponseResult<>(200,"回显成功",sysUserServiceFeign.findUserById(userId));
    }
    @ApiOperation(value = "新增信息", httpMethod = "POST", notes = "新增信息")
    @RequestMapping(value = "addUser")
    public ResponseResult addUser(@RequestBody SysUser sysUser){
        try {
            sysUserServiceFeign.addUser(sysUser);
            return new ResponseResult<>(200,"新增成功");
        }catch (Exception e) {
            e.printStackTrace();
            return new ResponseResult(444, "新增失败！");
        }
    }
    @ApiOperation(value = "删除信息", httpMethod = "GET", notes = "删除信息")
    @RequestMapping(value = "delUser")
    public ResponseResult delUser(@RequestParam(value = "userId")Long userId){
        try {
            sysUserServiceFeign.delUser(userId);
            return new ResponseResult<>(200,"删除成功");
        } catch (Exception e) {
            e.printStackTrace();
            return new ResponseResult(444, "新增失败！");
        }
    }
    @ApiOperation(value = "修改信息", httpMethod = "POST", notes = "修改信息")
    @RequestMapping(value = "updateUser")
    public ResponseResult updateUser(@RequestBody SysUser sysUser){
        try {
            sysUserServiceFeign.updateUser(sysUser);
            return new ResponseResult<>(200,"修改成功");
        } catch (Exception e) {
            e.printStackTrace();
            return new ResponseResult<>(444,"修改失败");
        }
    }
    @RequestMapping(value = "findAll")
    public ResponseResult<PagedResponse<SysUser>> findAll(@RequestBody SysUser sysUser,@RequestParam(value = "pageNum")Integer pageNum,@RequestParam(value = "pageSize")Integer pageSize){
        return new ResponseResult<>(200,"成功",sysUserServiceFeign.findAll(sysUser,pageNum,pageSize));
    }

    @ApiOperation(value = "获取教师信息列表",httpMethod = "POST",notes = "获取教师信息列表")
    @RequestMapping(value = "getTeachersList")
    public ResponseResult<List<SysUser>> getTeachersList(){
        return new ResponseResult<>(200,"获得教师信息列表成功",sysUserServiceFeign.getTeachersList());
    }

    @RequestMapping(value = "updateStatus")
    public ResponseResult updateStatus(@RequestBody SysUser sysUser){
        try {
            sysUserServiceFeign.updateStatus(sysUser);
            return new ResponseResult<>(200,"修改状态成功");
        } catch (Exception e) {
            e.printStackTrace();
            return new ResponseResult<>(444,"修改失败");
        }
    }

    @RequestMapping(value = "getDetails")
    public ResponseResult<List<SysUser>> getDetails(@RequestBody SysUser sysUser){
        return new ResponseResult<>(200,"获取详情人员信息成功",sysUserServiceFeign.getDetails(sysUser));
    }
}
